# To change this template, choose Tools | Templates
# and open the template in the editor.

class UndirectedGraph():
# An adjacency list implementation of Graph

    def __init__(self):
        # initializing dictionary
        self.graph = {}

    def addEdge(self,initialNode,finalNode):
        # adding finalNode to list of initialNode
        if (self.graph.__contains__(initialNode)):
            if ~(self.graph[initialNode].__contains__(finalNode)):
                self.graph[initialNode].append(finalNode)
        else:
            self.graph[initialNode] = [finalNode]

        # adding initialNode to list of finalNode
        if (self.graph.__contains__(finalNode)):
            if ~(self.graph[finalNode].__contains__(initialNode)):
                self.graph[finalNode].append(initialNode)
        else:
            self.graph[finalNode] = [initialNode]

    def getAdjacentEdges(self,node):
        return self.graph[node]


__author__="abhi"
__date__ ="$26 Mar, 2010 9:48:05 PM$"

if __name__ == "__main__":
    print "Hello World";

    a = UndirectedGraph();

    a.addEdge('a', 'b')
    a.addEdge('b', 'c')
    a.addEdge('a', 'b')
    a.addEdge('x', 'y')
    a.addEdge('y', 'z')
    a.addEdge('z', 'y')
    a.addEdge('x', 'z')
    a.addEdge('b', 'x')

    print(a.graph)
